
using System;
using System.IO;
using System.Runtime.Serialization;
using com.calitha.goldparser.lalr;
using com.calitha.commons;

namespace com.calitha.goldparser.sql
{

    [Serializable()]
    public class SymbolException : System.Exception
    {
        public SymbolException(string message)
            : base(message)
        {
        }

        public SymbolException(string message,
            Exception inner)
            : base(message, inner)
        {
        }

        protected SymbolException(SerializationInfo info,
            StreamingContext context)
            : base(info, context)
        {
        }

    }
    [Serializable()]
    public class RuleException : System.Exception
    {

        public RuleException(string message)
            : base(message)
        {
        }

        public RuleException(string message,
                             Exception inner)
            : base(message, inner)
        {
        }

        protected RuleException(SerializationInfo info,
                                StreamingContext context)
            : base(info, context)
        {
        }

    }
    enum SymbolConstants : int
    {
        SYMBOL_EOF = 0, // (EOF)
        SYMBOL_ERROR = 1, // (Error)
        SYMBOL_WHITESPACE = 2, // (Whitespace)
        SYMBOL_COMMENTEND = 3, // (Comment End)
        SYMBOL_COMMENTLINE = 4, // (Comment Line)
        SYMBOL_COMMENTSTART = 5, // (Comment Start)
        SYMBOL_MINUS = 6, // '-'
        SYMBOL_EXCLAMEQ = 7, // '!='
        SYMBOL_LPARAN = 8, // '('
        SYMBOL_RPARAN = 9, // ')'
        SYMBOL_TIMES = 10, // '*'
        SYMBOL_COMMA = 11, // ','
        SYMBOL_DIV = 12, // '/'
        SYMBOL_PLUS = 13, // '+'
        SYMBOL_LT = 14, // '<'
        SYMBOL_LTEQ = 15, // '<='
        SYMBOL_LTGT = 16, // '<>'
        SYMBOL_EQ = 17, // '='
        SYMBOL_GT = 18, // '>'
        SYMBOL_GTEQ = 19, // '>='
        SYMBOL_ADD = 20, // ADD
        SYMBOL_ALL = 21, // ALL
        SYMBOL_ALTER = 22, // ALTER
        SYMBOL_AND = 23, // AND
        SYMBOL_ASC = 24, // ASC
        SYMBOL_AVG = 25, // Avg
        SYMBOL_BETWEEN = 26, // BETWEEN
        SYMBOL_BIT = 27, // BIT
        SYMBOL_BY = 28, // BY
        SYMBOL_CHARACTER = 29, // CHARACTER
        SYMBOL_COLUMN = 30, // COLUMN
        SYMBOL_CONSTRAINT = 31, // CONSTRAINT
        SYMBOL_COUNT = 32, // Count
        SYMBOL_CREATE = 33, // CREATE
        SYMBOL_DATE = 34, // DATE
        SYMBOL_DECIMAL = 35, // DECIMAL
        SYMBOL_DELETE = 36, // DELETE
        SYMBOL_DESC = 37, // DESC
        SYMBOL_DISALLOW = 38, // DISALLOW
        SYMBOL_DISTINCT = 39, // DISTINCT
        SYMBOL_DROP = 40, // DROP
        SYMBOL_FLOAT = 41, // FLOAT
        SYMBOL_FOREIGN = 42, // FOREIGN
        SYMBOL_FROM = 43, // FROM
        SYMBOL_GROUP = 44, // GROUP
        SYMBOL_HAVING = 45, // HAVING
        SYMBOL_ID = 46, // Id
        SYMBOL_IGNORE = 47, // IGNORE
        SYMBOL_IN = 48, // IN
        SYMBOL_INDEX = 49, // INDEX
        SYMBOL_INNER = 50, // INNER
        SYMBOL_INSERT = 51, // INSERT
        SYMBOL_INTEGER = 52, // INTEGER
        SYMBOL_INTEGERLITERAL = 53, // IntegerLiteral
        SYMBOL_INTERVAL = 54, // INTERVAL
        SYMBOL_INTO = 55, // INTO
        SYMBOL_IS = 56, // IS
        SYMBOL_JOIN = 57, // JOIN
        SYMBOL_KEY = 58, // KEY
        SYMBOL_LEFT = 59, // LEFT
        SYMBOL_LIKE = 60, // LIKE
        SYMBOL_MAX = 61, // Max
        SYMBOL_MIN = 62, // Min
        SYMBOL_NOT = 63, // NOT
        SYMBOL_NULL = 64, // NULL
        SYMBOL_ON = 65, // ON
        SYMBOL_OR = 66, // OR
        SYMBOL_ORDER = 67, // ORDER
        SYMBOL_PRIMARY = 68, // PRIMARY
        SYMBOL_REAL = 69, // REAL
        SYMBOL_REALLITERAL = 70, // RealLiteral
        SYMBOL_REFERENCES = 71, // REFERENCES
        SYMBOL_RIGHT = 72, // RIGHT
        SYMBOL_SELECT = 73, // SELECT
        SYMBOL_SET = 74, // SET
        SYMBOL_SMALLINT = 75, // SMALLINT
        SYMBOL_STDEV = 76, // StDev
        SYMBOL_STDEVP = 77, // StDevP
        SYMBOL_STRINGLITERAL = 78, // StringLiteral
        SYMBOL_SUM = 79, // Sum
        SYMBOL_TABLE = 80, // TABLE
        SYMBOL_TIME = 81, // TIME
        SYMBOL_TIMESTAMP = 82, // TIMESTAMP
        SYMBOL_UNIQUE = 83, // UNIQUE
        SYMBOL_UPDATE = 84, // UPDATE
        SYMBOL_VALUES = 85, // VALUES
        SYMBOL_VAR = 86, // Var
        SYMBOL_VARP = 87, // VarP
        SYMBOL_WHERE = 88, // WHERE
        SYMBOL_WITH = 89, // WITH
        SYMBOL_ADDEXP = 90, // <Add Exp>
        SYMBOL_AGGREGATE = 91, // <Aggregate>
        SYMBOL_ALTERSTM = 92, // <Alter Stm>
        SYMBOL_ANDEXP = 93, // <And Exp>
        SYMBOL_ASSIGNLIST = 94, // <Assign List>
        SYMBOL_COLUMNITEM = 95, // <Column Item>
        SYMBOL_COLUMNLIST = 96, // <Column List>
        SYMBOL_COLUMNSOURCE = 97, // <Column Source>
        SYMBOL_COLUMNS = 98, // <Columns>
        SYMBOL_CONSTRAINT2 = 99, // <Constraint>
        SYMBOL_CONSTRAINTOPT = 100, // <Constraint Opt>
        SYMBOL_CONSTRAINTTYPE = 101, // <Constraint Type>
        SYMBOL_CREATESTM = 102, // <Create Stm>
        SYMBOL_DELETESTM = 103, // <Delete Stm>
        SYMBOL_DROPSTM = 104, // <Drop Stm>
        SYMBOL_EXPRLIST = 105, // <Expr List>
        SYMBOL_EXPRESSION = 106, // <Expression>
        SYMBOL_FIELDDEF = 107, // <Field Def>
        SYMBOL_FIELDDEFLIST = 108, // <Field Def List>
        SYMBOL_FROMCLAUSE = 109, // <From Clause>
        SYMBOL_GROUPCLAUSE = 110, // <Group Clause>
        SYMBOL_HAVINGCLAUSE = 111, // <Having Clause>
        SYMBOL_IDLIST = 112, // <ID List>
        SYMBOL_IDMEMBER = 113, // <Id Member>
        SYMBOL_INSERTSTM = 114, // <Insert Stm>
        SYMBOL_INTOCLAUSE = 115, // <Into Clause>
        SYMBOL_JOIN2 = 116, // <Join>
        SYMBOL_JOINCHAIN = 117, // <Join Chain>
        SYMBOL_MULTEXP = 118, // <Mult Exp>
        SYMBOL_NEGATEEXP = 119, // <Negate Exp>
        SYMBOL_NOTEXP = 120, // <Not Exp>
        SYMBOL_ORDERCLAUSE = 121, // <Order Clause>
        SYMBOL_ORDERLIST = 122, // <Order List>
        SYMBOL_ORDERTYPE = 123, // <Order Type>
        SYMBOL_PREDEXP = 124, // <Pred Exp>
        SYMBOL_QUERY = 125, // <Query>
        SYMBOL_RESTRICTION = 126, // <Restriction>
        SYMBOL_SELECTSTM = 127, // <Select Stm>
        SYMBOL_TUPLE = 128, // <Tuple>
        SYMBOL_TYPE = 129, // <Type>
        SYMBOL_UNIQUE2 = 130, // <Unique>
        SYMBOL_UPDATESTM = 131, // <Update Stm>
        SYMBOL_VALUE = 132, // <Value>
        SYMBOL_WHERECLAUSE = 133, // <Where Clause>
        SYMBOL_WITHCLAUSE = 134  // <With Clause>
    };
    public enum RuleConstants : int
    {
        RULE_QUERY = 0, // <Query> ::= <Alter Stm>
        RULE_QUERY2 = 1, // <Query> ::= <Create Stm>
        RULE_QUERY3 = 2, // <Query> ::= <Delete Stm>
        RULE_QUERY4 = 3, // <Query> ::= <Drop Stm>
        RULE_QUERY5 = 4, // <Query> ::= <Insert Stm>
        RULE_QUERY6 = 5, // <Query> ::= <Select Stm>
        RULE_QUERY7 = 6, // <Query> ::= <Update Stm>
        RULE_ALTERSTM_ALTER_TABLE_ID_ADD_COLUMN = 7, // <Alter Stm> ::= ALTER TABLE Id ADD COLUMN <Field Def List> <Constraint Opt>
        RULE_ALTERSTM_ALTER_TABLE_ID_ADD = 8, // <Alter Stm> ::= ALTER TABLE Id ADD <Constraint>
        RULE_ALTERSTM_ALTER_TABLE_ID_DROP_COLUMN_ID = 9, // <Alter Stm> ::= ALTER TABLE Id DROP COLUMN Id
        RULE_ALTERSTM_ALTER_TABLE_ID_DROP_CONSTRAINT_ID = 10, // <Alter Stm> ::= ALTER TABLE Id DROP CONSTRAINT Id
        RULE_CREATESTM_CREATE_INDEX_INTEGERLITERAL_ON_ID_LPARAN_RPARAN = 11, // <Create Stm> ::= CREATE <Unique> INDEX IntegerLiteral ON Id '(' <Order List> ')' <With Clause>
        RULE_CREATESTM_CREATE_TABLE_ID_LPARAN_RPARAN = 12, // <Create Stm> ::= CREATE TABLE Id '(' <ID List> ')' <Constraint Opt>
        RULE_UNIQUE_UNIQUE = 13, // <Unique> ::= UNIQUE
        RULE_UNIQUE = 14, // <Unique> ::= 
        RULE_WITHCLAUSE_WITH_PRIMARY = 15, // <With Clause> ::= WITH PRIMARY
        RULE_WITHCLAUSE_WITH_DISALLOW_NULL = 16, // <With Clause> ::= WITH DISALLOW NULL
        RULE_WITHCLAUSE_WITH_IGNORE_NULL = 17, // <With Clause> ::= WITH IGNORE NULL
        RULE_WITHCLAUSE = 18, // <With Clause> ::= 
        RULE_FIELDDEF_ID_NOT_NULL = 19, // <Field Def> ::= Id <Type> NOT NULL
        RULE_FIELDDEF_ID = 20, // <Field Def> ::= Id <Type>
        RULE_FIELDDEFLIST_COMMA = 21, // <Field Def List> ::= <Field Def> ',' <Field Def List>
        RULE_FIELDDEFLIST = 22, // <Field Def List> ::= <Field Def>
        RULE_TYPE_BIT = 23, // <Type> ::= BIT
        RULE_TYPE_DATE = 24, // <Type> ::= DATE
        RULE_TYPE_TIME = 25, // <Type> ::= TIME
        RULE_TYPE_TIMESTAMP = 26, // <Type> ::= TIMESTAMP
        RULE_TYPE_DECIMAL = 27, // <Type> ::= DECIMAL
        RULE_TYPE_REAL = 28, // <Type> ::= REAL
        RULE_TYPE_FLOAT = 29, // <Type> ::= FLOAT
        RULE_TYPE_SMALLINT = 30, // <Type> ::= SMALLINT
        RULE_TYPE_INTEGER = 31, // <Type> ::= INTEGER
        RULE_TYPE_INTERVAL = 32, // <Type> ::= INTERVAL
        RULE_TYPE_CHARACTER = 33, // <Type> ::= CHARACTER
        RULE_CONSTRAINTOPT = 34, // <Constraint Opt> ::= <Constraint>
        RULE_CONSTRAINTOPT2 = 35, // <Constraint Opt> ::= 
        RULE_CONSTRAINT_CONSTRAINT_ID = 36, // <Constraint> ::= CONSTRAINT Id <Constraint Type>
        RULE_CONSTRAINT_CONSTRAINT_ID2 = 37, // <Constraint> ::= CONSTRAINT Id
        RULE_CONSTRAINTTYPE_PRIMARY_KEY_LPARAN_RPARAN = 38, // <Constraint Type> ::= PRIMARY KEY '(' <ID List> ')'
        RULE_CONSTRAINTTYPE_UNIQUE_LPARAN_RPARAN = 39, // <Constraint Type> ::= UNIQUE '(' <ID List> ')'
        RULE_CONSTRAINTTYPE_NOT_NULL_LPARAN_RPARAN = 40, // <Constraint Type> ::= NOT NULL '(' <ID List> ')'
        RULE_CONSTRAINTTYPE_FOREIGN_KEY_LPARAN_RPARAN_REFERENCES_ID_LPARAN_RPARAN = 41, // <Constraint Type> ::= FOREIGN KEY '(' <ID List> ')' REFERENCES Id '(' <ID List> ')'
        RULE_DROPSTM_DROP_TABLE_ID = 42, // <Drop Stm> ::= DROP TABLE Id
        RULE_DROPSTM_DROP_INDEX_ID_ON_ID = 43, // <Drop Stm> ::= DROP INDEX Id ON Id
        RULE_INSERTSTM_INSERT_INTO_ID_LPARAN_RPARAN = 44, // <Insert Stm> ::= INSERT INTO Id '(' <ID List> ')' <Select Stm>
        RULE_INSERTSTM_INSERT_INTO_ID_LPARAN_RPARAN_VALUES_LPARAN_RPARAN = 45, // <Insert Stm> ::= INSERT INTO Id '(' <ID List> ')' VALUES '(' <Expr List> ')'
        RULE_UPDATESTM_UPDATE_ID_SET = 46, // <Update Stm> ::= UPDATE Id SET <Assign List> <Where Clause>
        RULE_ASSIGNLIST_ID_EQ_COMMA = 47, // <Assign List> ::= Id '=' <Expression> ',' <Assign List>
        RULE_ASSIGNLIST_ID_EQ = 48, // <Assign List> ::= Id '=' <Expression>
        RULE_DELETESTM_DELETE_FROM_ID = 49, // <Delete Stm> ::= DELETE FROM Id <Where Clause>
        RULE_SELECTSTM_SELECT = 50, // <Select Stm> ::= SELECT <Columns> <Into Clause> <From Clause> <Where Clause> <Group Clause> <Having Clause> <Order Clause>
        RULE_COLUMNS_TIMES = 51, // <Columns> ::= <Restriction> '*'
        RULE_COLUMNS = 52, // <Columns> ::= <Restriction> <Column List>
        RULE_COLUMNLIST_COMMA = 53, // <Column List> ::= <Column Item> ',' <Column List>
        RULE_COLUMNLIST = 54, // <Column List> ::= <Column Item>
        RULE_COLUMNITEM = 55, // <Column Item> ::= <Column Source>
        RULE_COLUMNITEM_ID = 56, // <Column Item> ::= <Column Source> Id
        RULE_COLUMNSOURCE = 57, // <Column Source> ::= <Aggregate>
        RULE_COLUMNSOURCE_ID = 58, // <Column Source> ::= Id
        RULE_RESTRICTION_ALL = 59, // <Restriction> ::= ALL
        RULE_RESTRICTION_DISTINCT = 60, // <Restriction> ::= DISTINCT
        RULE_RESTRICTION = 61, // <Restriction> ::= 
        RULE_AGGREGATE_COUNT_LPARAN_TIMES_RPARAN = 62, // <Aggregate> ::= Count '(' '*' ')'
        RULE_AGGREGATE_COUNT_LPARAN_RPARAN = 63, // <Aggregate> ::= Count '(' <Expression> ')'
        RULE_AGGREGATE_AVG_LPARAN_RPARAN = 64, // <Aggregate> ::= Avg '(' <Expression> ')'
        RULE_AGGREGATE_MIN_LPARAN_RPARAN = 65, // <Aggregate> ::= Min '(' <Expression> ')'
        RULE_AGGREGATE_MAX_LPARAN_RPARAN = 66, // <Aggregate> ::= Max '(' <Expression> ')'
        RULE_AGGREGATE_STDEV_LPARAN_RPARAN = 67, // <Aggregate> ::= StDev '(' <Expression> ')'
        RULE_AGGREGATE_STDEVP_LPARAN_RPARAN = 68, // <Aggregate> ::= StDevP '(' <Expression> ')'
        RULE_AGGREGATE_SUM_LPARAN_RPARAN = 69, // <Aggregate> ::= Sum '(' <Expression> ')'
        RULE_AGGREGATE_VAR_LPARAN_RPARAN = 70, // <Aggregate> ::= Var '(' <Expression> ')'
        RULE_AGGREGATE_VARP_LPARAN_RPARAN = 71, // <Aggregate> ::= VarP '(' <Expression> ')'
        RULE_INTOCLAUSE_INTO_ID = 72, // <Into Clause> ::= INTO Id
        RULE_INTOCLAUSE = 73, // <Into Clause> ::= 
        RULE_FROMCLAUSE_FROM = 74, // <From Clause> ::= FROM <ID List> <Join Chain>
        RULE_JOINCHAIN = 75, // <Join Chain> ::= <Join> <Join Chain>
        RULE_JOINCHAIN2 = 76, // <Join Chain> ::= 
        RULE_JOIN_INNER_JOIN_ON_ID_EQ_ID = 77, // <Join> ::= INNER JOIN <ID List> ON Id '=' Id
        RULE_JOIN_LEFT_JOIN_ON_ID_EQ_ID = 78, // <Join> ::= LEFT JOIN <ID List> ON Id '=' Id
        RULE_JOIN_RIGHT_JOIN_ON_ID_EQ_ID = 79, // <Join> ::= RIGHT JOIN <ID List> ON Id '=' Id
        RULE_JOIN_JOIN_ON_ID_EQ_ID = 80, // <Join> ::= JOIN <ID List> ON Id '=' Id
        RULE_WHERECLAUSE_WHERE = 81, // <Where Clause> ::= WHERE <Expression>
        RULE_WHERECLAUSE = 82, // <Where Clause> ::= 
        RULE_GROUPCLAUSE_GROUP_BY = 83, // <Group Clause> ::= GROUP BY <ID List>
        RULE_GROUPCLAUSE = 84, // <Group Clause> ::= 
        RULE_ORDERCLAUSE_ORDER_BY = 85, // <Order Clause> ::= ORDER BY <Order List>
        RULE_ORDERCLAUSE = 86, // <Order Clause> ::= 
        RULE_ORDERLIST_ID_COMMA = 87, // <Order List> ::= Id <Order Type> ',' <Order List>
        RULE_ORDERLIST_ID = 88, // <Order List> ::= Id <Order Type>
        RULE_ORDERTYPE_ASC = 89, // <Order Type> ::= ASC
        RULE_ORDERTYPE_DESC = 90, // <Order Type> ::= DESC
        RULE_ORDERTYPE = 91, // <Order Type> ::= 
        RULE_HAVINGCLAUSE_HAVING = 92, // <Having Clause> ::= HAVING <Expression>
        RULE_HAVINGCLAUSE = 93, // <Having Clause> ::= 
        RULE_EXPRESSION_OR = 94, // <Expression> ::= <And Exp> OR <Expression>
        RULE_EXPRESSION = 95, // <Expression> ::= <And Exp>
        RULE_ANDEXP_AND = 96, // <And Exp> ::= <Not Exp> AND <And Exp>
        RULE_ANDEXP = 97, // <And Exp> ::= <Not Exp>
        RULE_NOTEXP_NOT = 98, // <Not Exp> ::= NOT <Pred Exp>
        RULE_NOTEXP = 99, // <Not Exp> ::= <Pred Exp>
        RULE_PREDEXP_BETWEEN_AND = 100, // <Pred Exp> ::= <Add Exp> BETWEEN <Add Exp> AND <Add Exp>
        RULE_PREDEXP_NOT_BETWEEN_AND = 101, // <Pred Exp> ::= <Add Exp> NOT BETWEEN <Add Exp> AND <Add Exp>
        RULE_PREDEXP_IS_NOT_NULL = 102, // <Pred Exp> ::= <Value> IS NOT NULL
        RULE_PREDEXP_IS_NULL = 103, // <Pred Exp> ::= <Value> IS NULL
        RULE_PREDEXP_LIKE_STRINGLITERAL = 104, // <Pred Exp> ::= <Add Exp> LIKE StringLiteral
        RULE_PREDEXP_IN = 105, // <Pred Exp> ::= <Add Exp> IN <Tuple>
        RULE_PREDEXP_EQ = 106, // <Pred Exp> ::= <Add Exp> '=' <Add Exp>
        RULE_PREDEXP_LTGT = 107, // <Pred Exp> ::= <Add Exp> '<>' <Add Exp>
        RULE_PREDEXP_EXCLAMEQ = 108, // <Pred Exp> ::= <Add Exp> '!=' <Add Exp>
        RULE_PREDEXP_GT = 109, // <Pred Exp> ::= <Add Exp> '>' <Add Exp>
        RULE_PREDEXP_GTEQ = 110, // <Pred Exp> ::= <Add Exp> '>=' <Add Exp>
        RULE_PREDEXP_LT = 111, // <Pred Exp> ::= <Add Exp> '<' <Add Exp>
        RULE_PREDEXP_LTEQ = 112, // <Pred Exp> ::= <Add Exp> '<=' <Add Exp>
        RULE_PREDEXP = 113, // <Pred Exp> ::= <Add Exp>
        RULE_ADDEXP_PLUS = 114, // <Add Exp> ::= <Add Exp> '+' <Mult Exp>
        RULE_ADDEXP_MINUS = 115, // <Add Exp> ::= <Add Exp> '-' <Mult Exp>
        RULE_ADDEXP = 116, // <Add Exp> ::= <Mult Exp>
        RULE_MULTEXP_TIMES = 117, // <Mult Exp> ::= <Mult Exp> '*' <Negate Exp>
        RULE_MULTEXP_DIV = 118, // <Mult Exp> ::= <Mult Exp> '/' <Negate Exp>
        RULE_MULTEXP = 119, // <Mult Exp> ::= <Negate Exp>
        RULE_NEGATEEXP_MINUS = 120, // <Negate Exp> ::= '-' <Value>
        RULE_NEGATEEXP = 121, // <Negate Exp> ::= <Value>
        RULE_VALUE = 122, // <Value> ::= <Tuple>
        RULE_VALUE_ID = 123, // <Value> ::= Id
        RULE_VALUE_INTEGERLITERAL = 124, // <Value> ::= IntegerLiteral
        RULE_VALUE_REALLITERAL = 125, // <Value> ::= RealLiteral
        RULE_VALUE_STRINGLITERAL = 126, // <Value> ::= StringLiteral
        RULE_VALUE_NULL = 127, // <Value> ::= NULL
        RULE_TUPLE_LPARAN_RPARAN = 128, // <Tuple> ::= '(' <Select Stm> ')'
        RULE_TUPLE_LPARAN_RPARAN2 = 129, // <Tuple> ::= '(' <Expr List> ')'
        RULE_EXPRLIST_COMMA = 130, // <Expr List> ::= <Expression> ',' <Expr List>
        RULE_EXPRLIST = 131, // <Expr List> ::= <Expression>
        RULE_IDLIST_COMMA = 132, // <ID List> ::= <Id Member> ',' <ID List>
        RULE_IDLIST = 133, // <ID List> ::= <Id Member>
        RULE_IDMEMBER_ID = 134, // <Id Member> ::= Id
        RULE_IDMEMBER_ID_ID = 135  // <Id Member> ::= Id Id
    };
    public class MyParser
    {
        protected LALRParser parser;

        public MyParser(string filename)
        {
            FileStream stream = new FileStream(filename,
                                               FileMode.Open,
                                               FileAccess.Read,
                                               FileShare.Read);
            Init(stream);
            stream.Close();
        }

        public MyParser(string baseName, string resourceName)
        {
            byte[] buffer = ResourceUtil.GetByteArrayResource(
                System.Reflection.Assembly.GetExecutingAssembly(),
                baseName,
                resourceName);
            MemoryStream stream = new MemoryStream(buffer);
            Init(stream);
            stream.Close();
        }

        public MyParser(Stream stream)
        {
            Init(stream);
        }

        private void Init(Stream stream)
        {
            CGTReader reader = new CGTReader(stream);
            parser = reader.CreateNewParser();
            parser.TrimReductions = false;
            parser.StoreTokens = LALRParser.StoreTokensMode.NoUserObject;

            parser.OnReduce += new LALRParser.ReduceHandler(ReduceEvent);
            parser.OnTokenRead += new LALRParser.TokenReadHandler(TokenReadEvent);
            parser.OnAccept += new LALRParser.AcceptHandler(AcceptEvent);
            parser.OnTokenError += new LALRParser.TokenErrorHandler(TokenErrorEvent);
            parser.OnParseError += new LALRParser.ParseErrorHandler(ParseErrorEvent);
        }

        public void Parse(string source)
        {
            parser.Parse(source);

        }

        private void TokenReadEvent(LALRParser parser, TokenReadEventArgs args)
        {
            try
            {
                args.Token.UserObject = CreateObject(args.Token);
            }
            catch (Exception e)
            {
                args.Continue = false;
                //todo: Report message to UI?
            }
        }

        private Object CreateObject(TerminalToken token)
        {
            switch (token.Symbol.Id)
            {
                case (int)SymbolConstants.SYMBOL_EOF:
                    //(EOF)
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_ERROR:
                    //(Error)
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_WHITESPACE:
                    //(Whitespace)
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_COMMENTEND:
                    //(Comment End)
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_COMMENTLINE:
                    //(Comment Line)
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_COMMENTSTART:
                    //(Comment Start)
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_MINUS:
                    //'-'
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_EXCLAMEQ:
                    //'!='
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_LPARAN:
                    //'('
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_RPARAN:
                    //')'
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_TIMES:
                    //'*'
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_COMMA:
                    //','
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_DIV:
                    //'/'
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_PLUS:
                    //'+'
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_LT:
                    //'<'
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_LTEQ:
                    //'<='
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_LTGT:
                    //'<>'
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_EQ:
                    //'='
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_GT:
                    //'>'
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_GTEQ:
                    //'>='
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_ADD:
                    //ADD
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_ALL:
                    //ALL
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_ALTER:
                    //ALTER
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_AND:
                    //AND
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_ASC:
                    //ASC
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_AVG:
                    //Avg
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_BETWEEN:
                    //BETWEEN
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_BIT:
                    //BIT
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_BY:
                    //BY
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_CHARACTER:
                    //CHARACTER
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_COLUMN:
                    //COLUMN
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_CONSTRAINT:
                    //CONSTRAINT
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_COUNT:
                    //Count
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_CREATE:
                    //CREATE
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_DATE:
                    //DATE
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_DECIMAL:
                    //DECIMAL
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_DELETE:
                    //DELETE
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_DESC:
                    //DESC
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_DISALLOW:
                    //DISALLOW
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_DISTINCT:
                    //DISTINCT
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_DROP:
                    //DROP
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_FLOAT:
                    //FLOAT
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_FOREIGN:
                    //FOREIGN
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_FROM:
                    //FROM
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_GROUP:
                    //GROUP
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_HAVING:
                    //HAVING
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_ID:
                    //Id
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_IGNORE:
                    //IGNORE
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_IN:
                    //IN
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_INDEX:
                    //INDEX
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_INNER:
                    //INNER
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_INSERT:
                    //INSERT
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_INTEGER:
                    //INTEGER
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_INTEGERLITERAL:
                    //IntegerLiteral
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_INTERVAL:
                    //INTERVAL
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_INTO:
                    //INTO
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_IS:
                    //IS
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_JOIN:
                    //JOIN
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_KEY:
                    //KEY
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_LEFT:
                    //LEFT
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_LIKE:
                    //LIKE
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_MAX:
                    //Max
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_MIN:
                    //Min
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_NOT:
                    //NOT
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_NULL:
                    //NULL
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_ON:
                    //ON
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_OR:
                    //OR
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_ORDER:
                    //ORDER
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_PRIMARY:
                    //PRIMARY
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_REAL:
                    //REAL
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_REALLITERAL:
                    //RealLiteral
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_REFERENCES:
                    //REFERENCES
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_RIGHT:
                    //RIGHT
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_SELECT:
                    //SELECT
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_SET:
                    //SET
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_SMALLINT:
                    //SMALLINT
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_STDEV:
                    //StDev
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_STDEVP:
                    //StDevP
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_STRINGLITERAL:
                    //StringLiteral
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_SUM:
                    //Sum
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_TABLE:
                    //TABLE
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_TIME:
                    //TIME
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_TIMESTAMP:
                    //TIMESTAMP
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_UNIQUE:
                    //UNIQUE
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_UPDATE:
                    //UPDATE
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_VALUES:
                    //VALUES
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_VAR:
                    //Var
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_VARP:
                    //VarP
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_WHERE:
                    //WHERE
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_WITH:
                    //WITH
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_ADDEXP:
                    //<Add Exp>
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_AGGREGATE:
                    //<Aggregate>
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_ALTERSTM:
                    //<Alter Stm>
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_ANDEXP:
                    //<And Exp>
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_ASSIGNLIST:
                    //<Assign List>
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_COLUMNITEM:
                    //<Column Item>
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_COLUMNLIST:
                    //<Column List>
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_COLUMNSOURCE:
                    //<Column Source>
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_COLUMNS:
                    //<Columns>
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_CONSTRAINT2:
                    //<Constraint>
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_CONSTRAINTOPT:
                    //<Constraint Opt>
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_CONSTRAINTTYPE:
                    //<Constraint Type>
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_CREATESTM:
                    //<Create Stm>
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_DELETESTM:
                    //<Delete Stm>
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_DROPSTM:
                    //<Drop Stm>
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_EXPRLIST:
                    //<Expr List>
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_EXPRESSION:
                    //<Expression>
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_FIELDDEF:
                    //<Field Def>
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_FIELDDEFLIST:
                    //<Field Def List>
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_FROMCLAUSE:
                    //<From Clause>
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_GROUPCLAUSE:
                    //<Group Clause>
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_HAVINGCLAUSE:
                    //<Having Clause>
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_IDLIST:
                    //<ID List>
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_IDMEMBER:
                    //<Id Member>
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_INSERTSTM:
                    //<Insert Stm>
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_INTOCLAUSE:
                    //<Into Clause>
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_JOIN2:
                    //<Join>
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_JOINCHAIN:
                    //<Join Chain>
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_MULTEXP:
                    //<Mult Exp>
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_NEGATEEXP:
                    //<Negate Exp>
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_NOTEXP:
                    //<Not Exp>
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_ORDERCLAUSE:
                    //<Order Clause>
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_ORDERLIST:
                    //<Order List>
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_ORDERTYPE:
                    //<Order Type>
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_PREDEXP:
                    //<Pred Exp>
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_QUERY:
                    //<Query>
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_RESTRICTION:
                    //<Restriction>
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_SELECTSTM:
                    //<Select Stm>
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_TUPLE:
                    //<Tuple>
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_TYPE:
                    //<Type>
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_UNIQUE2:
                    //<Unique>
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_UPDATESTM:
                    //<Update Stm>
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_VALUE:
                    //<Value>
                    //todo: Create a new object that corresponds to the symbol
                    return null;

                case (int)SymbolConstants.SYMBOL_WHERECLAUSE:
                    //<Where Clause>
                    //todo: Create a new object that corresponds to the symbol


                    return null;

                case (int)SymbolConstants.SYMBOL_WITHCLAUSE:
                    //<With Clause>
                    //todo: Create a new object that corresponds to the symbol
                    return null;

            }
            throw new SymbolException("Unknown symbol");
        }

        private void ReduceEvent(LALRParser parser, ReduceEventArgs args)
        {
            try
            {
                args.Token.UserObject = CreateObject(args.Token);
            }
            catch (Exception e)
            {
                args.Continue = false;
                //todo: Report message to UI?
            }
        }

        public static Object CreateObject(NonterminalToken token)
        {
            switch (token.Rule.Id)
            {
                case (int)RuleConstants.RULE_QUERY:
                    //<Query> ::= <Alter Stm>
                    //todo: Create a new object using the stored user objects.
                    return null;

                case (int)RuleConstants.RULE_QUERY2:
                    //<Query> ::= <Create Stm>
                    //todo: Create a new object using the stored user objects.
                    return null;

                case (int)RuleConstants.RULE_QUERY3:
                    //<Query> ::= <Delete Stm>
                    return (Statements)token.Tokens[0].UserObject;
                 
                case (int)RuleConstants.RULE_QUERY4:
                    //<Query> ::= <Drop Stm>
                    //todo: Create a new object using the stored user objects.
                    return null;

                case (int)RuleConstants.RULE_QUERY5:
                    //<Query> ::= <Insert Stm>
                    //todo: Create a new object using the stored user objects.
                    return (Statements)token.Tokens[0].UserObject;
                    

                case (int)RuleConstants.RULE_QUERY6:
                    //<Query> ::= <Select Stm>
                    return (Statements)token.Tokens[0].UserObject;

                case (int)RuleConstants.RULE_QUERY7:
                    //<Query> ::= <Update Stm>
                    return (Statements)token.Tokens[0].UserObject;

                case (int)RuleConstants.RULE_ALTERSTM_ALTER_TABLE_ID_ADD_COLUMN:
                    //<Alter Stm> ::= ALTER TABLE Id ADD COLUMN <Field Def List> <Constraint Opt>
                    //todo: Create a new object using the stored user objects.
                    return null;

                case (int)RuleConstants.RULE_ALTERSTM_ALTER_TABLE_ID_ADD:
                    //<Alter Stm> ::= ALTER TABLE Id ADD <Constraint>
                    //todo: Create a new object using the stored user objects.
                    return null;

                case (int)RuleConstants.RULE_ALTERSTM_ALTER_TABLE_ID_DROP_COLUMN_ID:
                    //<Alter Stm> ::= ALTER TABLE Id DROP COLUMN Id
                    //todo: Create a new object using the stored user objects.
                    return null;

                case (int)RuleConstants.RULE_ALTERSTM_ALTER_TABLE_ID_DROP_CONSTRAINT_ID:
                    //<Alter Stm> ::= ALTER TABLE Id DROP CONSTRAINT Id
                    //todo: Create a new object using the stored user objects.
                    return null;

                case (int)RuleConstants.RULE_CREATESTM_CREATE_INDEX_INTEGERLITERAL_ON_ID_LPARAN_RPARAN:
                    //<Create Stm> ::= CREATE <Unique> INDEX IntegerLiteral ON Id '(' <Order List> ')' <With Clause>
                    //todo: Create a new object using the stored user objects.
                    return null;

                case (int)RuleConstants.RULE_CREATESTM_CREATE_TABLE_ID_LPARAN_RPARAN:
                    //<Create Stm> ::= CREATE TABLE Id '(' <ID List> ')' <Constraint Opt>
                    //todo: Create a new object using the stored user objects.
                    return null;

                case (int)RuleConstants.RULE_UNIQUE_UNIQUE:
                    //<Unique> ::= UNIQUE
                    //todo: Create a new object using the stored user objects.
                    return null;

                case (int)RuleConstants.RULE_UNIQUE:
                    //<Unique> ::= 
                    //todo: Create a new object using the stored user objects.
                    return null;

                case (int)RuleConstants.RULE_WITHCLAUSE_WITH_PRIMARY:
                    //<With Clause> ::= WITH PRIMARY
                    //todo: Create a new object using the stored user objects.
                    return null;

                case (int)RuleConstants.RULE_WITHCLAUSE_WITH_DISALLOW_NULL:
                    //<With Clause> ::= WITH DISALLOW NULL
                    //todo: Create a new object using the stored user objects.
                    return null;

                case (int)RuleConstants.RULE_WITHCLAUSE_WITH_IGNORE_NULL:
                    //<With Clause> ::= WITH IGNORE NULL
                    //todo: Create a new object using the stored user objects.
                    return null;

                case (int)RuleConstants.RULE_WITHCLAUSE:
                    //<With Clause> ::= 
                    //todo: Create a new object using the stored user objects.
                    return null;

                case (int)RuleConstants.RULE_FIELDDEF_ID_NOT_NULL:
                    //<Field Def> ::= Id <Type> NOT NULL
                    //todo: Create a new object using the stored user objects.
                    return null;

                case (int)RuleConstants.RULE_FIELDDEF_ID:
                    //<Field Def> ::= Id <Type>
                    //todo: Create a new object using the stored user objects.
                    return null;

                case (int)RuleConstants.RULE_FIELDDEFLIST_COMMA:
                    //<Field Def List> ::= <Field Def> ',' <Field Def List>
                    //todo: Create a new object using the stored user objects.
                    return null;

                case (int)RuleConstants.RULE_FIELDDEFLIST:
                    //<Field Def List> ::= <Field Def>
                    //todo: Create a new object using the stored user objects.
                    return null;

                case (int)RuleConstants.RULE_TYPE_BIT:
                    //<Type> ::= BIT
                    //todo: Create a new object using the stored user objects.
                    return null;

                case (int)RuleConstants.RULE_TYPE_DATE:
                    //<Type> ::= DATE
                    //todo: Create a new object using the stored user objects.
                    return null;

                case (int)RuleConstants.RULE_TYPE_TIME:
                    //<Type> ::= TIME
                    //todo: Create a new object using the stored user objects.
                    return null;

                case (int)RuleConstants.RULE_TYPE_TIMESTAMP:
                    //<Type> ::= TIMESTAMP
                    //todo: Create a new object using the stored user objects.
                    return null;

                case (int)RuleConstants.RULE_TYPE_DECIMAL:
                    //<Type> ::= DECIMAL
                    //todo: Create a new object using the stored user objects.
                    return null;

                case (int)RuleConstants.RULE_TYPE_REAL:
                    //<Type> ::= REAL
                    //todo: Create a new object using the stored user objects.
                    return null;

                case (int)RuleConstants.RULE_TYPE_FLOAT:
                    //<Type> ::= FLOAT
                    //todo: Create a new object using the stored user objects.
                    return null;

                case (int)RuleConstants.RULE_TYPE_SMALLINT:
                    //<Type> ::= SMALLINT
                    //todo: Create a new object using the stored user objects.
                    return null;

                case (int)RuleConstants.RULE_TYPE_INTEGER:
                    //<Type> ::= INTEGER
                    //todo: Create a new object using the stored user objects.
                    return null;

                case (int)RuleConstants.RULE_TYPE_INTERVAL:
                    //<Type> ::= INTERVAL
                    //todo: Create a new object using the stored user objects.
                    return null;

                case (int)RuleConstants.RULE_TYPE_CHARACTER:
                    //<Type> ::= CHARACTER
                    //todo: Create a new object using the stored user objects.
                    return null;

                case (int)RuleConstants.RULE_CONSTRAINTOPT:
                    //<Constraint Opt> ::= <Constraint>
                    //todo: Create a new object using the stored user objects.
                    return null;

                case (int)RuleConstants.RULE_CONSTRAINTOPT2:
                    //<Constraint Opt> ::= 
                    //todo: Create a new object using the stored user objects.
                    return null;

                case (int)RuleConstants.RULE_CONSTRAINT_CONSTRAINT_ID:
                    //<Constraint> ::= CONSTRAINT Id <Constraint Type>
                    //todo: Create a new object using the stored user objects.
                    return null;

                case (int)RuleConstants.RULE_CONSTRAINT_CONSTRAINT_ID2:
                    //<Constraint> ::= CONSTRAINT Id
                    //todo: Create a new object using the stored user objects.
                    return null;

                case (int)RuleConstants.RULE_CONSTRAINTTYPE_PRIMARY_KEY_LPARAN_RPARAN:
                    //<Constraint Type> ::= PRIMARY KEY '(' <ID List> ')'
                    //todo: Create a new object using the stored user objects.
                    return null;

                case (int)RuleConstants.RULE_CONSTRAINTTYPE_UNIQUE_LPARAN_RPARAN:
                    //<Constraint Type> ::= UNIQUE '(' <ID List> ')'
                    //todo: Create a new object using the stored user objects.
                    return null;

                case (int)RuleConstants.RULE_CONSTRAINTTYPE_NOT_NULL_LPARAN_RPARAN:
                    //<Constraint Type> ::= NOT NULL '(' <ID List> ')'
                    //todo: Create a new object using the stored user objects.
                    return null;

                case (int)RuleConstants.RULE_CONSTRAINTTYPE_FOREIGN_KEY_LPARAN_RPARAN_REFERENCES_ID_LPARAN_RPARAN:
                    //<Constraint Type> ::= FOREIGN KEY '(' <ID List> ')' REFERENCES Id '(' <ID List> ')'
                    //todo: Create a new object using the stored user objects.
                    return null;

                case (int)RuleConstants.RULE_DROPSTM_DROP_TABLE_ID:
                    //<Drop Stm> ::= DROP TABLE Id
                    //todo: Create a new object using the stored user objects.
                    return null;

                case (int)RuleConstants.RULE_DROPSTM_DROP_INDEX_ID_ON_ID:
                    //<Drop Stm> ::= DROP INDEX Id ON Id
                    //todo: Create a new object using the stored user objects.
                    return null;

                case (int)RuleConstants.RULE_INSERTSTM_INSERT_INTO_ID_LPARAN_RPARAN:
                    //<Insert Stm> ::= INSERT INTO Id '(' <ID List> ')' <Select Stm>
                    if (token.Tokens[7].UserObject != null) return (Statements)token.Tokens[7].UserObject;
                    else return new Statements();

                case (int)RuleConstants.RULE_INSERTSTM_INSERT_INTO_ID_LPARAN_RPARAN_VALUES_LPARAN_RPARAN:
                    //<Insert Stm> ::= INSERT INTO Id '(' <ID List> ')' VALUES '(' <Expr List> ')'
                    Statements statement = new Statements();
                    InsertStm insert = new InsertStm();
                    statement.ListInserts.Add(insert);
                    insert.IdList = (IdList)token.Tokens[4].UserObject;
                    insert.ExprList = (ExpressionList)token.Tokens[8].UserObject;
                    return statement;

                case (int)RuleConstants.RULE_UPDATESTM_UPDATE_ID_SET:
                    //<Update Stm> ::= UPDATE Id SET <Assign List> <Where Clause>
                    statement = new Statements();
                    UpdateStm updateStm = new UpdateStm();
                    updateStm.AssignList = (AssignList)token.Tokens[3].UserObject;
                    updateStm.WhereExpresion = (Expression)token.Tokens[4].UserObject;
                    statement.ListUpdate.Add(updateStm);
                    return statement;

                case (int)RuleConstants.RULE_ASSIGNLIST_ID_EQ_COMMA:
                    //<Assign List> ::= Id '=' <Expression> ',' <Assign List>
                    Assign newAssign=new Assign();
                    newAssign.Id = (TerminalToken) token.Tokens[0];
                    newAssign.Expression = (Expression)token.Tokens[2].UserObject;
                    AssignList listAsign = (AssignList)token.Tokens[4].UserObject;
                    listAsign.Add(newAssign);
                    return listAsign;

                case (int)RuleConstants.RULE_ASSIGNLIST_ID_EQ:
                    //<Assign List> ::= Id '=' <Expression>
                    listAsign = new AssignList();
                    newAssign = new Assign();
                    newAssign.Id = (TerminalToken)token.Tokens[0];
                    newAssign.Expression = (Expression)token.Tokens[2].UserObject;
                    listAsign.Add(newAssign);
                    return listAsign;

                case (int)RuleConstants.RULE_DELETESTM_DELETE_FROM_ID:
                    //<Delete Stm> ::= DELETE FROM Id <Where Clause>
                    statement = new Statements();
                    DeleteStm delete=new DeleteStm();
                    delete.Expression=(Expression)token.Tokens[3].UserObject;
                    statement.ListDelete.Add(delete);
                    return statement;

                case (int)RuleConstants.RULE_SELECTSTM_SELECT:
                    //<Select Stm> ::= SELECT <Columns> <Into Clause> <From Clause> <Where Clause> <Group Clause> <Having Clause> <Order Clause>
                    Statements stm = new Statements();
                    SelectStm select = new SelectStm();
                    select.WhereExpresion = (Expression)token.Tokens[4].UserObject;
                    select.HavingExpresion = (Expression)token.Tokens[6].UserObject;
                    stm.ListSelect.Add(select);
                    return stm;

                case (int)RuleConstants.RULE_COLUMNS_TIMES:
                    //<Columns> ::= <Restriction> '*'
                    //todo: Create a new object using the stored user objects.
                    return null;

                case (int)RuleConstants.RULE_COLUMNS:
                    //<Columns> ::= <Restriction> <Column List>
                    //todo: Create a new object using the stored user objects.
                    return null;

                case (int)RuleConstants.RULE_COLUMNLIST_COMMA:
                    //<Column List> ::= <Column Item> ',' <Column List>
                    //todo: Create a new object using the stored user objects.
                    return null;

                case (int)RuleConstants.RULE_COLUMNLIST:
                    //<Column List> ::= <Column Item>
                    //todo: Create a new object using the stored user objects.
                    return null;

                case (int)RuleConstants.RULE_COLUMNITEM:
                    //<Column Item> ::= <Column Source>
                    //todo: Create a new object using the stored user objects.
                    return null;

                case (int)RuleConstants.RULE_COLUMNITEM_ID:
                    //<Column Item> ::= <Column Source> Id
                    //todo: Create a new object using the stored user objects.
                    return null;

                case (int)RuleConstants.RULE_COLUMNSOURCE:
                    //<Column Source> ::= <Aggregate>
                    //todo: Create a new object using the stored user objects.
                    return null;

                case (int)RuleConstants.RULE_COLUMNSOURCE_ID:
                    //<Column Source> ::= Id
                    //todo: Create a new object using the stored user objects.
                    return null;

                case (int)RuleConstants.RULE_RESTRICTION_ALL:
                    //<Restriction> ::= ALL
                    //todo: Create a new object using the stored user objects.
                    return null;

                case (int)RuleConstants.RULE_RESTRICTION_DISTINCT:
                    //<Restriction> ::= DISTINCT
                    //todo: Create a new object using the stored user objects.
                    return null;

                case (int)RuleConstants.RULE_RESTRICTION:
                    //<Restriction> ::= 
                    //todo: Create a new object using the stored user objects.
                    return null;

                case (int)RuleConstants.RULE_AGGREGATE_COUNT_LPARAN_TIMES_RPARAN:
                    //<Aggregate> ::= Count '(' '*' ')'
                    //todo: Create a new object using the stored user objects.
                    return null;

                case (int)RuleConstants.RULE_AGGREGATE_COUNT_LPARAN_RPARAN:
                    //<Aggregate> ::= Count '(' <Expression> ')'
                    //todo: Create a new object using the stored user objects.
                    return null;

                case (int)RuleConstants.RULE_AGGREGATE_AVG_LPARAN_RPARAN:
                    //<Aggregate> ::= Avg '(' <Expression> ')'
                    //todo: Create a new object using the stored user objects.
                    return null;

                case (int)RuleConstants.RULE_AGGREGATE_MIN_LPARAN_RPARAN:
                    //<Aggregate> ::= Min '(' <Expression> ')'
                    //todo: Create a new object using the stored user objects.
                    return null;

                case (int)RuleConstants.RULE_AGGREGATE_MAX_LPARAN_RPARAN:
                    //<Aggregate> ::= Max '(' <Expression> ')'
                    //todo: Create a new object using the stored user objects.
                    return null;

                case (int)RuleConstants.RULE_AGGREGATE_STDEV_LPARAN_RPARAN:
                    //<Aggregate> ::= StDev '(' <Expression> ')'
                    //todo: Create a new object using the stored user objects.
                    return null;

                case (int)RuleConstants.RULE_AGGREGATE_STDEVP_LPARAN_RPARAN:
                    //<Aggregate> ::= StDevP '(' <Expression> ')'
                    //todo: Create a new object using the stored user objects.
                    return null;

                case (int)RuleConstants.RULE_AGGREGATE_SUM_LPARAN_RPARAN:
                    //<Aggregate> ::= Sum '(' <Expression> ')'
                    //todo: Create a new object using the stored user objects.
                    return null;

                case (int)RuleConstants.RULE_AGGREGATE_VAR_LPARAN_RPARAN:
                    //<Aggregate> ::= Var '(' <Expression> ')'
                    //todo: Create a new object using the stored user objects.
                    return null;

                case (int)RuleConstants.RULE_AGGREGATE_VARP_LPARAN_RPARAN:
                    //<Aggregate> ::= VarP '(' <Expression> ')'
                    //todo: Create a new object using the stored user objects.
                    return null;

                case (int)RuleConstants.RULE_INTOCLAUSE_INTO_ID:
                    //<Into Clause> ::= INTO Id
                    //todo: Create a new object using the stored user objects.
                    return null;

                case (int)RuleConstants.RULE_INTOCLAUSE:
                    //<Into Clause> ::= 
                    //todo: Create a new object using the stored user objects.
                    return null;

                case (int)RuleConstants.RULE_FROMCLAUSE_FROM:
                    //<From Clause> ::= FROM <ID List> <Join Chain>
                    //todo: Create a new object using the stored user objects.
                    return null;

                case (int)RuleConstants.RULE_JOINCHAIN:
                    //<Join Chain> ::= <Join> <Join Chain>
                    //todo: Create a new object using the stored user objects.
                    return null;

                case (int)RuleConstants.RULE_JOINCHAIN2:
                    //<Join Chain> ::= 
                    //todo: Create a new object using the stored user objects.
                    return null;

                case (int)RuleConstants.RULE_JOIN_INNER_JOIN_ON_ID_EQ_ID:
                    //<Join> ::= INNER JOIN <ID List> ON Id '=' Id
                    //todo: Create a new object using the stored user objects.
                    return null;

                case (int)RuleConstants.RULE_JOIN_LEFT_JOIN_ON_ID_EQ_ID:
                    //<Join> ::= LEFT JOIN <ID List> ON Id '=' Id
                    //todo: Create a new object using the stored user objects.
                    return null;

                case (int)RuleConstants.RULE_JOIN_RIGHT_JOIN_ON_ID_EQ_ID:
                    //<Join> ::= RIGHT JOIN <ID List> ON Id '=' Id
                    //todo: Create a new object using the stored user objects.
                    return null;

                case (int)RuleConstants.RULE_JOIN_JOIN_ON_ID_EQ_ID:
                    //<Join> ::= JOIN <ID List> ON Id '=' Id
                    //todo: Create a new object using the stored user objects.
                    return null;

                case (int)RuleConstants.RULE_WHERECLAUSE_WHERE:
                    //<Where Clause> ::= WHERE <Expression>
                    return (Expression)token.Tokens[1].UserObject;
                    

                case (int)RuleConstants.RULE_WHERECLAUSE:
                    //<Where Clause> ::= 
                    //todo: Create a new object using the stored user objects.
                    return new Expression();

                case (int)RuleConstants.RULE_GROUPCLAUSE_GROUP_BY:
                    //<Group Clause> ::= GROUP BY <ID List>
                    //todo: Create a new object using the stored user objects.
                    return null;

                case (int)RuleConstants.RULE_GROUPCLAUSE:
                    //<Group Clause> ::= 
                    //todo: Create a new object using the stored user objects.
                    return null;

                case (int)RuleConstants.RULE_ORDERCLAUSE_ORDER_BY:
                    //<Order Clause> ::= ORDER BY <Order List>
                    //todo: Create a new object using the stored user objects.
                    return null;

                case (int)RuleConstants.RULE_ORDERCLAUSE:
                    //<Order Clause> ::= 
                    //todo: Create a new object using the stored user objects.
                    return null;

                case (int)RuleConstants.RULE_ORDERLIST_ID_COMMA:
                    //<Order List> ::= Id <Order Type> ',' <Order List>
                    //todo: Create a new object using the stored user objects.
                    return null;

                case (int)RuleConstants.RULE_ORDERLIST_ID:
                    //<Order List> ::= Id <Order Type>
                    //todo: Create a new object using the stored user objects.
                    return null;

                case (int)RuleConstants.RULE_ORDERTYPE_ASC:
                    //<Order Type> ::= ASC
                    //todo: Create a new object using the stored user objects.
                    return null;

                case (int)RuleConstants.RULE_ORDERTYPE_DESC:
                    //<Order Type> ::= DESC
                    //todo: Create a new object using the stored user objects.
                    return null;

                case (int)RuleConstants.RULE_ORDERTYPE:
                    //<Order Type> ::= 
                    //todo: Create a new object using the stored user objects.
                    return null;

                case (int)RuleConstants.RULE_HAVINGCLAUSE_HAVING:
                    //<Having Clause> ::= HAVING <Expression>
                    return (Expression)token.Tokens[1].UserObject;

                case (int)RuleConstants.RULE_HAVINGCLAUSE:
                    //<Having Clause> ::= 
                    return new Expression();

                case (int)RuleConstants.RULE_EXPRESSION_OR:
                    //<Expression> ::= <And Exp> OR <Expression>
                    Expression orExp = (Expression)token.Tokens[0].UserObject;
                    orExp.AddExpression((Expression)token.Tokens[2].UserObject);
                    return orExp;

                case (int)RuleConstants.RULE_EXPRESSION:
                    //<Expression> ::= <And Exp>
                    return (Expression)token.Tokens[0].UserObject;

                case (int)RuleConstants.RULE_ANDEXP_AND:
                    //<And Exp> ::= <Not Exp> AND <And Exp>
                    //todo: Create a new object using the stored user objects.
                    Expression andExp = (Expression)token.Tokens[0].UserObject;
                    andExp.AddExpression((Expression)token.Tokens[2].UserObject);
                    return andExp;

                case (int)RuleConstants.RULE_ANDEXP:
                    //<And Exp> ::= <Not Exp>
                    //todo: Create a new object using the stored user objects.
                    return (Expression)token.Tokens[0].UserObject; 

                case (int)RuleConstants.RULE_NOTEXP_NOT:
                    //<Not Exp> ::= NOT <Pred Exp>
                    Expression expNot = new Expression();
                    expNot.Enqueue((PredExp)token.Tokens[1].UserObject);
                    return expNot;

                case (int)RuleConstants.RULE_NOTEXP:
                    //<Not Exp> ::= <Pred Exp>
                    expNot = new Expression();
                    expNot.Enqueue((PredExp)token.Tokens[0].UserObject);
                    return expNot;

                case (int)RuleConstants.RULE_PREDEXP_BETWEEN_AND:
                    //<Pred Exp> ::= <Add Exp> BETWEEN <Add Exp> AND <Add Exp>
                    PredExp exAddBetweenAnd = (PredExp)token.Tokens[0].UserObject;
                    exAddBetweenAnd.AddExpresion((PredExp)token.Tokens[2].UserObject);
                    exAddBetweenAnd.AddExpresion((PredExp)token.Tokens[4].UserObject);
                    return exAddBetweenAnd;

                    

                case (int)RuleConstants.RULE_PREDEXP_NOT_BETWEEN_AND:
                    //<Pred Exp> ::= <Add Exp> NOT BETWEEN <Add Exp> AND <Add Exp>
                    PredExp exAddNotBetweenAnd = (PredExp)token.Tokens[0].UserObject;
                    exAddNotBetweenAnd.AddExpresion((PredExp)token.Tokens[3].UserObject);
                    exAddNotBetweenAnd.AddExpresion((PredExp)token.Tokens[5].UserObject);
                    return exAddNotBetweenAnd;

                case (int)RuleConstants.RULE_PREDEXP_IS_NOT_NULL:
                    //<Pred Exp> ::= <Value> IS NOT NULL
                    //we do the same as in the next rule, don't put a break here    

                case (int)RuleConstants.RULE_PREDEXP_IS_NULL:
                    //<Pred Exp> ::= <Value> IS NULL
                    return (PredExp)token.Tokens[0].UserObject;
                    

                case (int)RuleConstants.RULE_PREDEXP_LIKE_STRINGLITERAL:
                    //<Pred Exp> ::= <Add Exp> LIKE StringLiteral
                    PredExp exAdd = (PredExp)token.Tokens[0].UserObject;
                    exAdd.ListStrings.Add((TerminalToken) token.Tokens[2]);
                    return exAdd;

                case (int)RuleConstants.RULE_PREDEXP_IN:
                    //<Pred Exp> ::= <Add Exp> IN <Tuple>
                    //we do the same as in the next rule, don't put a break here 

                case (int)RuleConstants.RULE_PREDEXP_EQ:
                    //<Pred Exp> ::= <Add Exp> '=' <Add Exp>
                //we do the same as in the next rule, don't put a break here 

                case (int)RuleConstants.RULE_PREDEXP_LTGT:
                    //<Pred Exp> ::= <Add Exp> '<>' <Add Exp>
                //we do the same as in the next rule, don't put a break here 

                case (int)RuleConstants.RULE_PREDEXP_EXCLAMEQ:
                    //<Pred Exp> ::= <Add Exp> '!=' <Add Exp>
                //we do the same as in the next rule, don't put a break here 

                case (int)RuleConstants.RULE_PREDEXP_GT:
                    //<Pred Exp> ::= <Add Exp> '>' <Add Exp>
                //we do the same as in the next rule, don't put a break here 

                case (int)RuleConstants.RULE_PREDEXP_GTEQ:
                    //<Pred Exp> ::= <Add Exp> '>=' <Add Exp>
                //we do the same as in the next rule, don't put a break here 

                case (int)RuleConstants.RULE_PREDEXP_LT:
                    //<Pred Exp> ::= <Add Exp> '<' <Add Exp>
                //we do the same as in the next rule, don't put a break here 

                case (int)RuleConstants.RULE_PREDEXP_LTEQ:
                    //<Pred Exp> ::= <Add Exp> '<=' <Add Exp>
                    PredExp exComparation = new PredExp();
                    exComparation.AddExpresion((PredExp)token.Tokens[0].UserObject);
                    exComparation.AddExpresion((PredExp)token.Tokens[2].UserObject);
                    return exComparation;
                    
                case (int)RuleConstants.RULE_PREDEXP:
                    //<Pred Exp> ::= <Add Exp>
                    return (PredExp)token.Tokens[0].UserObject;

                case (int)RuleConstants.RULE_ADDEXP_PLUS:
                    //<Add Exp> ::= <Add Exp> '+' <Mult Exp>
                    //we do the same as in the next rule, don't put a break here 

                case (int)RuleConstants.RULE_ADDEXP_MINUS:
                    //<Add Exp> ::= <Add Exp> '-' <Mult Exp>
                    PredExp exMultRest = new PredExp();
                    exMultRest.AddExpresion((PredExp)token.Tokens[0].UserObject);
                    exMultRest.AddExpresion((PredExp)token.Tokens[2].UserObject);
                    return exMultRest;

                case (int)RuleConstants.RULE_ADDEXP:
                    //<Add Exp> ::= <Mult Exp>
                    return (PredExp)token.Tokens[0].UserObject;

                case (int)RuleConstants.RULE_MULTEXP_TIMES:
                    //<Mult Exp> ::= <Mult Exp> '*' <Negate Exp>
                    //we do the same as in the next rule, don't put a break here

                case (int)RuleConstants.RULE_MULTEXP_DIV:
                    //<Mult Exp> ::= <Mult Exp> '/' <Negate Exp>
                    PredExp exMultDiv = new PredExp();
                    exMultDiv.AddExpresion((PredExp)token.Tokens[0].UserObject);
                    exMultDiv.AddExpresion((PredExp)token.Tokens[2].UserObject);
                    return exMultDiv;

                case (int)RuleConstants.RULE_MULTEXP:
                    //<Mult Exp> ::= <Negate Exp>
                    return (PredExp)token.Tokens[0].UserObject;

                case (int)RuleConstants.RULE_NEGATEEXP_MINUS:
                    //<Negate Exp> ::= '-' <Value>
                    return (PredExp)token.Tokens[1].UserObject;

                case (int)RuleConstants.RULE_NEGATEEXP:
                    //<Negate Exp> ::= <Value>
                    return (PredExp)token.Tokens[0].UserObject;

                case (int)RuleConstants.RULE_VALUE:
                    //<Value> ::= <Tuple>
                    PredExp pe = new PredExp();
                    pe.Tuple.AddTuple((Tuple)token.Tokens[0].UserObject);
                    return pe;

                case (int)RuleConstants.RULE_VALUE_ID:
                    //<Value> ::= Id
                    PredExp exID = new PredExp();
                    exID.ListIDs.Add((TerminalToken)token.Tokens[0]);
                    return exID;

                case (int)RuleConstants.RULE_VALUE_INTEGERLITERAL:
                    //<Value> ::= IntegerLiteral
                    PredExp exInteger = new PredExp();
                    exInteger.ListIntegers.Add((TerminalToken)token.Tokens[0]);
                    return exInteger;

                case (int)RuleConstants.RULE_VALUE_REALLITERAL:
                    //<Value> ::= RealLiteral
                    PredExp exReal = new PredExp();
                    exReal.ListReals.Add((TerminalToken)token.Tokens[0]);
                    return exReal;

                case (int)RuleConstants.RULE_VALUE_STRINGLITERAL:
                    //<Value> ::= StringLiteral
                    PredExp exString = new PredExp();
                    exString.ListStrings.Add((TerminalToken)token.Tokens[0]);
                    return exString;

                case (int)RuleConstants.RULE_VALUE_NULL:
                    //<Value> ::= NULL
                    return new PredExp(); //null is null, everywhere
                    
                case (int)RuleConstants.RULE_TUPLE_LPARAN_RPARAN:
                    //<Tuple> ::= '(' <Select Stm> ')'
                    Tuple tupleSelect=new Tuple();
                    tupleSelect.StatementTuple.AddStatements((Statements)token.Tokens[1].UserObject);
                    return tupleSelect; 

                case (int)RuleConstants.RULE_TUPLE_LPARAN_RPARAN2:
                    //<Tuple> ::= '(' <Expr List> ')'
                    Tuple tupleExprList = new Tuple();
                    tupleExprList.ExpresionListTuple.AddExpressionList((ExpressionList)token.Tokens[1].UserObject);
                    return tupleExprList;

                case (int)RuleConstants.RULE_EXPRLIST_COMMA:
                    //<Expr List> ::= <Expression> ',' <Expr List>
                    ExpressionList listExpr = (ExpressionList)token.Tokens[2].UserObject;
                    listExpr.Enqueue((Expression)token.Tokens[0].UserObject);
                    return listExpr;

                case (int)RuleConstants.RULE_EXPRLIST:
                    //<Expr List> ::= <Expression>
                    listExpr = new ExpressionList();
                    listExpr.Enqueue((Expression)token.Tokens[0].UserObject);
                    return listExpr;
                    

                case (int)RuleConstants.RULE_IDLIST_COMMA:
                    //<ID List> ::= <Id Member> ',' <ID List>
                    IdList idList = (IdList)token.Tokens[2].UserObject;
                    idList.Enqueue((IdMember)token.Tokens[0].UserObject);
                    return idList;


                case (int)RuleConstants.RULE_IDLIST:
                    //<ID List> ::= <Id Member>
                    IdList listId = new IdList();
                    listId.Enqueue((IdMember)token.Tokens[0].UserObject);
                    return listId;

                case (int)RuleConstants.RULE_IDMEMBER_ID:
                    //<Id Member> ::= Id
                    IdMember id = new IdMember();
                    id.Id = (TerminalToken)token.Tokens[0];
                    return id;

                case (int)RuleConstants.RULE_IDMEMBER_ID_ID:
                    //<Id Member> ::= Id Id
                    id = new IdMember();
                    id.Id = (TerminalToken)token.Tokens[0];
                    return id;

            }
            throw new RuleException("Unknown rule");
        }

        protected void AcceptEvent(LALRParser parser, AcceptEventArgs args)
        {
            
        }

        private void TokenErrorEvent(LALRParser parser, TokenErrorEventArgs args)
        {
            string message = "Token error with input: '" + args.Token.ToString() + "'";
            //todo: Report message to UI?
        }

        private void ParseErrorEvent(LALRParser parser, ParseErrorEventArgs args)
        {
            string message = "Parse error caused by token: '" + args.UnexpectedToken.ToString() + "'";
            //todo: Report message to UI?
        }


    }
}
